<?php 
class perusahaan_model extends CI_model{

	function list_perusahaan(){
		$this->db->select('*');
		$this->db->from('perusahaan');
		$this->db->order_by('perusahaan.id_perusahaan', 'DESC');
		$q = $this->db->get();
		return $q->result();
	}

	

	function get_perusahaan(){
		$this->db->select('*');
		$this->db->from('perusahaan');
		$this->db->order_by('perusahaan.id_perusahaan', 'DESC');
		$this->db->limit('1');
		$q = $this->db->get();
		return $q->result();
	}

	function list_kontak(){
		$this->db->select('*');
		$this->db->from('kontak');
		$q = $this->db->get();
		return $q->result();
	}

	function get_perusahaan_search($keyword){
		$q = $this->db->query("SELECT * 
								FROM perusahaan
								WHERE nama_perusahaan LIKE '%$keyword%'
								ORDER BY nama_perusahaan DESC
								");

		return $q->result();
	}

	function get_id_penugasan_marketing($id_perusahaan){
		$q = $this->db->query("SELECT id_penugasan_marketing 
								FROM penugasan_marketing
								WHERE id_perusahaan=$id_perusahaan
								");

		$ret = $q->result();
		return $ret[0]->id_penugasan_marketing;
	}

	function get_page($db, $where){
		$this->db->where($where);
		$q = $this->db->get($db);

		return $q->result_array();
	}

	function get_sudah_marketing(){
		$q = $this->db->query("SELECT * 
								FROM perusahaan
								WHERE status_marketing_perusahaan <> 'belum'
								ORDER BY status_marketing_perusahaan DESC
								");

		return $q->result();
	}

	function detail_hasil($id){
		$q = $this->db->query("SELECT *
							   FROM penugasan_followup pf
							   JOIN 
							   (SELECT p.id_perusahaan,p.nama_perusahaan,pm.waktu_marketing, p.status_marketing_perusahaan, p.kategori_perusahaan, p.alamat_perusahaan, p.longitude_perusahaan, p.latitude_perusahaan, p.keterangan_perusahaan, pm.id_penugasan_marketing, pm.deskripsi_hasil_marketing, pm.id_marketer, m.nama_marketer
							   FROM penugasan_marketing pm
							   JOIN 
							   perusahaan p ON pm.id_perusahaan=p.id_perusahaan
							   JOIN 
							   marketer m ON pm.id_marketer=m.id_marketer
							   ) m ON pf.id_penugasan_marketing=m.id_penugasan_marketing
							   JOIN
							   teknisi t ON pf.id_teknisi=t.id_teknisi
							   WHERE m.id_perusahaan=$id");
		return $q->result();
	}



}

?>